home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks ’92 / Sound Asleep / Sound Asleep Source / soundasleep.a next >
Encoding:
Text File  |  1992-06-19  |  3.4 KB  |  135 lines  |  [TEXT/MPS ]

  1. ;
  2. ;    Sound Asleep
  3. ;    ©1992 David Thompson
  4. ;
  5. ;    A little hack to audibly let the user know when the PowerBook is either going
  6. ;    to sleep or waking up. There is also a C portion to this appliction.
  7. ;
  8.     SEG        'Main'
  9.     CASE    OFF        
  10.     PRINT    PUSH
  11.     PRINT    OFF
  12.  
  13.     INCLUDE    'PowerEqu.a'
  14.     INCLUDE    'Traps.a'
  15.  
  16.     PRINT    POP
  17.  
  18.     IMPORT    playthatsound
  19. ;
  20. ;    This is the Procedure called by the Power Manager to ask/tell the process that
  21. ;    it's bedtime. This procedure is also called to wake up the process in case it
  22. ;    wants to do something (like play a sound!).
  23. ;
  24. ;    As part of the hack, this routine is also called by the C source to store the
  25. ;    handles to the two sound resources in a space which is not A5 relative so that
  26. ;    the procedure can execute even when it is not the current application.
  27. ;
  28.  
  29. soundasleep    PROC    EXPORT
  30.  
  31. StackFrame    RECORD    {A6Link},DECR
  32. ParamBegin    EQU        *
  33. ParamSize    EQU        ParamBegin-*
  34. RetAddr        DS.L    1
  35. A6Link        DS.L    1
  36. LocalSize    EQU        *
  37.             ENDR
  38.             
  39.             WITH    StackFrame
  40.             LINK    A6,#LocalSize
  41.  
  42.             CMPI.L    #sleepRequest,D0    ; is this a network sleep request?
  43.             BNE.S    @1
  44. ;            JSR        RequestSleep    ; we don't do anything special on network requests
  45.             MOVE.L    #0,D0            ; so we can always sleep (return 0 in D0)
  46.             BRA.S    Exit
  47.  
  48. @1            CMPI.L    #sleepDemand,D0    ; are we being told to go to sleep?
  49.             BNE.S    @2
  50.             MOVE.L    yawnHndl,-(A7)
  51.             JSR        playthatsound
  52.             BRA.S    Exit
  53.  
  54. @2            CMPI.L    #sleepWakeUp,D0    ; are we being told to wake up?
  55.             BNE.S    @3
  56.             MOVE.L    wakeHndl,-(A7)
  57.             JSR        playthatsound
  58.             BRA.S    Exit
  59.  
  60. @3            CMPI.L    #sleepRevoke,D0    ; is a network sleep request being cancelled?
  61.             BNE.S    sethandles
  62. ;            JSR        RevokeRequest    ; since we don't do anything on a request, do nothing here too
  63.             BRA.S    Exit
  64.  
  65. ;    If we haven't been called with any of the above selectors, we're being called to
  66. ;    store the Yawn and Wakeup sound handles. There is a static counter which is set
  67. ;    to -1 initially. We see what value the counter is so we know which handle is
  68. ;    being passed in D0.
  69.  
  70. sethandles    LEA        counter,A0
  71.             MOVE.L    D1,-(SP)
  72.             MOVE.W    (A0),D1        ; save D1 on the stack because we use it
  73.             CMPI.W    #-1,D1        ; if counter is -1, save the yawn handle
  74.             BEQ.S    setyawn
  75.             CMPI.W    #0,D1        ; if counter is 0, save the wakeup handle
  76.             BEQ.S    setwake
  77.             BRA.S    restoreD1    ; otherwise, we're done (called by accident?)
  78. setyawn        ADDQ.W    #1,(A0)
  79.             LEA        yawnHndl,A0
  80.             MOVE.L    D0,(A0)
  81.             BRA.S    restoreD1
  82. setwake        ADDQ.W    #1,(A0)
  83.             LEA        wakeHndl,A0
  84.             MOVE.L    D0,(A0)
  85. restoreD1    MOVE.L    (SP)+,D1    ; restore D1
  86.  
  87. Exit        UNLK    A6
  88.             MOVEA.L    (SP)+,A0
  89.             ADDA.L    #ParamSize,SP
  90.             JMP        (A0)
  91.  
  92. counter        DC.W    -1
  93. yawnHndl    DC.L    0
  94. wakeHndl    DC.L    0
  95.  
  96.             ENDP
  97. ;
  98. ;    This routine is called from our C source to get the yawn and wake handles
  99. ;    saved in some global variables that are accessable to the above procedure
  100. ;    even if this Application isn't the current one.
  101. ;
  102. ;    I had to call this routine because the above routine expected the handles
  103. ;    passed in D0 and there was no easy way to do this from C without embedding
  104. ;    some assembler in the C code (and I couldn't remember how to do this without
  105. ;    the manuals).
  106. ;
  107.  
  108. soundHandleSetup    PROC    EXPORT
  109.  
  110. StackFrame1    RECORD    {A6Link1},DECR
  111. ParamBegin1    EQU        *
  112. YAWNARG        DS.L    1
  113. WAKEARG        DS.L    1
  114. ParamSize1    EQU        ParamBegin1-*
  115. RetAddr1    DS.L    1
  116. A6Link1        DS.L    1
  117. LocalSize1    EQU        *
  118.             ENDR
  119.  
  120.             WITH    StackFrame1
  121.             LINK    A6,#LocalSize1
  122.  
  123.             MOVE.L    12(SP),D0
  124.             JSR        soundasleep
  125.             MOVE.L    8(SP),D0
  126.             JSR        soundasleep
  127.             UNLK    A6
  128.             MOVEA.L    (SP)+,A0
  129.             ADDA.L    #ParamSize1,SP
  130.             JMP        (A0)
  131.  
  132.             ENDP
  133.  
  134.             END
  135.